home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / demobook / shelves.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  22.9 KB  |  925 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include <gl.h>
  19. #include <math.h>
  20. #include <device.h>
  21. #include <string.h>
  22. #include <unistd.h>
  23. #include "exbookglo.h"
  24. #include "shelves.h"
  25. #include "exglobals.h"
  26.  
  27. void resetshelfcolors()
  28. {
  29.     color_mult = 1.0;
  30.     morecolors[shelfcolor][0] = 138;
  31.     morecolors[shelfcolor][1] = 84;
  32.     morecolors[shelfcolor][2] = 51;
  33. /* good purple color
  34.     morecolors[shelfcolor][0] = 102;
  35.     morecolors[shelfcolor][1] = 0;
  36.     morecolors[shelfcolor][2] = 179;
  37. */
  38. /*
  39.     morecolors[shelflight][0] = 133;
  40.     morecolors[shelflight][1] = 63;
  41.     morecolors[shelflight][2] = 225;
  42.     morecolors[shelflight2][0] = 123;
  43.     morecolors[shelflight2][1] = 63;
  44.     morecolors[shelflight2][2] = 209;
  45.     morecolors[shelfdark][0] = 55;
  46.     morecolors[shelfdark][1] = 0;
  47.     morecolors[shelfdark][2] = 102;
  48. */
  49. }
  50.  
  51. void setshelfcolor(float carray[3])
  52. {
  53.     carray[0] = (float) morecolors[shelfcolor][0] / 255.0 * color_mult;
  54.     carray[1] = (float) morecolors[shelfcolor][1] / 255.0 * color_mult;
  55.     carray[2] = (float) morecolors[shelfcolor][2] / 255.0 * color_mult;
  56.     /*
  57.      * printf(" color set to %f %f %f  mult = %f\n", carray[0], carray[1],
  58.      * carray[2], color_mult); 
  59.      */
  60. }
  61.  
  62. void movebookonshelf(int booknum, float newpos)
  63. {
  64.     bookpos[booknum] = newpos;
  65. }
  66.  
  67. void initxflip(int num)
  68. {
  69.     int             ndx, prevndx;
  70.     float           tmp;
  71.     float           xtincr;
  72.     int             i;
  73.  
  74.     xt[0] = bookpos[num];    /* this is the position of the book on the
  75.                  * shelf */
  76.     tmp = 7.0 / flipincr;
  77.     ndx = (int) (tmp +.5);
  78.     for (i = 1; i <= ndx; i++) {
  79.     xt[i] = xt[0];
  80.     }
  81.     prevndx = ndx;
  82.     ndx = ndx + (2.0 * ndx / 3.0);
  83.     for (i = prevndx + 1; i <= ndx; i++) {
  84.     xt[i] = xt[prevndx];
  85.     }
  86.     prevndx = ndx;
  87.     ndx = STEPS;
  88.     tmp = (float) (STEPS - prevndx);
  89.     xtincr = (-xt[0]) / tmp;
  90.     for (i = prevndx + 1; i < ndx; i++) {
  91.     xt[i] = xt[i - 1] + xtincr;
  92.     }
  93. }
  94.  
  95. void initflip(int whichshelf)   /* 0 = top shelf   1 = second shelf  */
  96. {
  97.     float           tmp;
  98.     float           xtincr, ytincr, ztincr, xrincr, yrincr, zrincr;
  99.     float           yti2, zti2;
  100.     int             i;
  101.     int             ndx, prevndx;
  102.     int             count;
  103.  
  104.     if (whichshelf == 0)    /* for the first shelf */
  105.     yt[0] = shelftop - outsidebevel - shelfface - shelfbevel - shelfheight +.125;
  106.     else
  107.     yt[0] = shelftop - outsidebevel - 2.0 * shelfface - 3.0 * shelfbevel - 2.0 * shelfheight + 1.0;
  108.     zt[0] = -87.0;
  109.     flipdistance = sqrt(yt[0] * yt[0] + zt[0] * zt[0]);
  110.     flipincr = flipdistance / (float) STEPS;
  111.     xr[0] = 0.0;
  112.     yr[0] = 0.0;
  113.     zr[0] = 0.0;
  114.     prevndx = 0;
  115.     xt2[0] = 0.0;
  116.     yt2[0] = 0.0;
  117.     zt2[0] = 0.0;
  118.  
  119.     /* pull back off of the shelf */
  120.     tmp = 7.0 / flipincr;
  121.     ndx = (int) (tmp +.5);
  122.     if (ndx > STEPS / 10)
  123.     ndx = STEPS / 10;
  124.     zt[ndx] = zt[0] + flipincr * ndx;
  125.     xr[ndx] = xr[0];
  126.     count = 1.0;
  127.     for (i = 1; i <= ndx; i++) {
  128.     yt[i] = yt[0];
  129.     zt[i] = zt[0] + flipincr * i;
  130.     xr[i] = xr[0];
  131.     yr[i] = yr[0];
  132.     zr[i] = zr[0];
  133.     xt2[i] = 0.0;
  134.     yt2[i] = 0.0;
  135.     zt2[i] = 0.0;
  136.     /* start x rotation */
  137.     if ((zt[i] - zt[0]) > 5.0) {
  138.         xr[i] = xr[i - 1] + count * 1.1;
  139.         zt2[i] = zt[i] + 85.0;
  140.         count++;
  141.     }
  142.     }
  143.     /* rotate around x as it falls off of the shelf */
  144.     prevndx = ndx;
  145.     ndx = ndx + (2.0 * ndx / 3.0);
  146.     zt[ndx] = zt[0] + flipincr * ndx;
  147.     count = 1;
  148.     xrincr = 1.1;
  149.     for (i = prevndx + 1; i <= ndx; i++) {
  150.     yt[i] = yt[prevndx];
  151.     zt[i] = zt[0] + flipincr * i;
  152.     xr[i] = xr[i - 1] + xrincr * (i - prevndx);
  153.     yr[i] = yr[prevndx];
  154.     zr[i] = zr[prevndx];
  155.     if ((zt[i] - zt[0]) > 10.0) {
  156.         zr[i] = zr[prevndx] + count * 1.1;
  157.         count++;
  158.     }
  159.     xt2[i] = 0.0;
  160.     yt2[i] = 0.0;
  161.     zt2[i] = zt[i] + 85.0;
  162.     }
  163.     /* add rotate around z  and start to move forward */
  164.     prevndx = ndx;
  165.     ndx = STEPS;
  166.     tmp = (float) (STEPS - prevndx) - 1;
  167.     ztincr = (10.5 - zt[prevndx]) / tmp;
  168.     ytincr = (-yt[prevndx] + 5.125) / tmp;
  169. /*    xtincr = (-xt[0] - 5.0) / tmp;    /* book ends 5 to the left (for
  170. /*                     * when open) */
  171.     xrincr = (155.0 - xr[prevndx]) / tmp;
  172.     yrincr = 0.0;
  173.     zrincr = (180.0 - zr[prevndx]) / tmp;
  174.  
  175.     for (i = prevndx + 1; i < ndx; i++) {
  176.     yt[i] = yt[i - 1] + ytincr;
  177.     zt[i] = zt[i - 1] + ztincr;
  178.     xr[i] = xr[i - 1] + xrincr;
  179.     if (xr[i] > 360.0)
  180.         xr[i] = xr[i] - 360.0;
  181.     yr[i] = yr[i - 1] + yrincr;
  182.     zr[i] = zr[i - 1] + zrincr;
  183.     if (zr[i] > 360.0)
  184.         zr[i] = zr[i] - 360.0;
  185.     xt2[i] = 0.0;
  186.     }
  187.     /* smooth  into the new rotate origin */
  188.     zti2 = (5.25 - zt2[prevndx]) / 19.0;
  189.     yti2 = (5.0 - yt2[prevndx]) / 19.0;
  190.     for (i = 1; i < 20; i++) {
  191.     yt2[i + prevndx] = yt2[i + prevndx - 1] + yti2;
  192.     zt2[i + prevndx] = zt2[i + prevndx - 1] + zti2;
  193.     }
  194.     i = i + prevndx;
  195.     while (i < STEPS) {
  196.     yt2[i] = yt2[i - 1];
  197.     zt2[i] = zt2[i - 1];
  198.     i++;
  199.     }
  200. }
  201.  
  202. void drawbookcase();
  203. void drawtitle(char *title);
  204.  
  205. void flipbook()
  206. {
  207.     int             i;
  208.     float           time1, time2;
  209.     float           increment = 1.0;
  210.     float           dx;
  211.     long            winsize_x, winsize_y;
  212.     int             startfade;
  213.     float           color_incr;
  214.  
  215.     if (numberofgroups > endfirstshelf) {
  216.     if (currentbook < endfirstshelf)
  217.         initflip(0);
  218.     else
  219.         initflip(1);
  220.     }
  221.     startfade = 0;
  222.     mkdoublebuffer();
  223.     if (getgdesc(GD_BITS_NORM_ZBUFFER) > 0) {
  224. /*    /* calculate time for 5 frames */
  225. /*     clock_sec(&time1);
  226. /*    for (i = 0; i < 5; i++) {
  227. /*        drawbookcase();
  228. /*        zbuffer(TRUE);
  229. /*        zclear();
  230. /*        pushmatrix();
  231. /*        translate(xt[i], yt[i], zt[i]);
  232. /*
  233. /*        rot(xr[i], 'x');
  234. /*        rot(yr[i], 'y');
  235. /*        rot(zr[i], 'z');
  236. /*
  237. /*        setcovercolor(curgroup);
  238. /*        pushmatrix();
  239. /*        translate(0.0, 0.0, 5.125);
  240. /*        rot(180.0, 'y');
  241. /*        translate(0.0, 0.0, -5.125);
  242. /*        drawopenframe(13);
  243. /*        drawtitle(curgroup->nameptr->string);
  244. /*        zbuffer(FALSE);
  245. /*
  246. /*
  247. /*        popmatrix();
  248. /*        popmatrix();
  249. /*        drawpdmenu(winsize_x, winsize_y);
  250. /*        dobookview();
  251. /*    }        
  252. /*    clock_sec(&time2);
  253. /*
  254. /*    /* divide projected time for 30 frames by target time of 3.5 seconds */
  255. /*    increment = ((time2 - time1) * 6) / 3.0;
  256. /*    if (increment < 1.0)
  257. /*        increment = 1.0;
  258. /*    printf("expected time = %f increment=%f\n",
  259. /*        ((time2 - time1) * 6.0), increment);
  260. */        
  261.     getsize(&winsize_x, &winsize_y);
  262. /*    clock_sec(&time1); */
  263.     color_incr = 1.0 / (float)STEPS;
  264.     for (dx = 0.0; dx < STEPS; dx += increment) {
  265.         i = (int) dx;
  266.         /* printf(" %d ",i); */
  267.         if (i >= startfade) {
  268.         color_mult = color_mult - color_incr;
  269.         if (color_mult < 0.0)
  270.             color_mult = 0.0;
  271.         }
  272.         if (i < 4) {
  273.         /* need zbuffer while book on top of shelf */
  274.         zbuffer(TRUE);
  275.         zclear();
  276.         drawbookcase();
  277.         } else {
  278.         drawbookcase();
  279.         zbuffer(TRUE);
  280.         zclear();
  281.         }
  282.         pushmatrix();
  283.         translate(xt[i], yt[i], zt[i]);
  284.  
  285.         rot(xr[i], 'x');
  286.         rot(yr[i], 'y');
  287.         rot(zr[i], 'z');
  288.  
  289.         setcovercolor(curgroup);
  290.         pushmatrix();
  291.         translate(0.0, 0.0, 5.125);
  292.         rot(180.0, 'y');
  293.         translate(0.0, 0.0, -5.125);
  294.         drawopenframe(13);
  295.             if (curgroup->ok || !Hide)
  296.            drawtitle(curgroup->nameptr->string);
  297.             else
  298.            drawtitle("Not Installed");
  299.         zbuffer(FALSE);
  300.  
  301.  
  302.         popmatrix();
  303.         popmatrix();
  304.         swapbuffers();
  305.     }
  306. /*    clock_sec(&time2); */
  307. /*    printf("\n %f seconds to finish  \n",time2-time1); */
  308.     }
  309. /*    /* end of if there's a zbuffer */
  310. /*    else
  311. /*    printf("\n\n   NO ZBUFFER!!! \n\n");
  312. */
  313. }
  314.  
  315. int find_blank(char *str)
  316. {
  317.     int             i;
  318.     int             len;
  319.     Boolean         found;
  320.  
  321.     found = FALSE;
  322.     i = 0;
  323.     len = strlen(str);
  324.     while (!found && i < len) {
  325.     if (str[i] == ' ')
  326.         found = TRUE;
  327.     else
  328.         i++;
  329.     }
  330.     if (!found)
  331.     i = -1;
  332.     return (i);
  333. }
  334.  
  335. void drawtitle(char *title)
  336. {
  337.     int             len;
  338.     char           *s1, *s2;
  339.     int             i;
  340. /*     char            blank = ' '; */
  341.  
  342.     s1 = NULL;
  343.     s2 = NULL;
  344.     len = strlen(title);
  345.     c3s(morecolors[White]);
  346.     pushmatrix();
  347.     rot(180.0, 'y');
  348.     translate(1.0, 2.0, 0.1);
  349.     rot(-90.0, 'z');
  350.     /*
  351.      * in stroke call, x moves the text up and down the spine of the book,
  352.      * smaller y moves the text to the left, larger y moves the text to the
  353.      * right.  
  354.      */
  355.     if (len <= 12)
  356.     stroke(-7.5, -1.3, 0.58,.09,.09, 1.0, title);
  357.     else if (len < 19)
  358.     stroke(-7.5, -1.3, 0.58,.06,.06, 1.0, title);
  359. /*
  360.     else if (len < 17)
  361.     stroke(-7.5, -1.3, 0.58,.07,.07, 1.0, title);
  362.     else if (len < 20)
  363.     stroke(-7.5, -1.3, 0.58,.06,.06, 1.0, title);
  364. */
  365.     else {
  366.     /* 19 characters can fit on the binding at this size */
  367.     i = find_blank(&(title[15]));
  368.     if (i == -1 || i > 5 || len > 37) {
  369.         s1 = (char *) malloc(20);
  370.         strncpy(s1, title, 17);
  371.         s1[15] = '.';
  372.         s1[16] = '.';
  373.         s1[17] = '.';
  374.         s1[18] = '\0';
  375.         stroke(-7.5, -1.3, 0.58,.06,.06, 1.0, s1);
  376.     } else {
  377.         i = i + 15;
  378.         s1 = (char *) malloc(i + 1);
  379.         strncpy(s1, title, i);
  380.         s1[i] = '\0';
  381.         stroke(-7.5, -.9, 0.58,.057,.057, 1.0, s1);
  382.         s2 = (char *) malloc(len - i);
  383.         strcpy(s2, &(title[i + 1]));
  384.         stroke(-7.5, -1.7, 0.58,.057,.057, 1.0, s2);
  385.     }
  386.     }
  387.     popmatrix();
  388.     if (s1 != NULL)
  389.     free(s1);
  390.     if (s2 != NULL)
  391.     free(s2);
  392. }
  393.  
  394. void shownewposition(int pos)
  395. {
  396.     float           y;
  397.     float half;
  398.  
  399.     half = (bookpos[1] - bookpos[0]) / 2.0;
  400.     dooverlayview();
  401.     color(PUP_WHITE);
  402. /*
  403.     y = shelftop - shelfface - outsidebevel - shelfbevel * 2.0 - shelfheight;
  404. */
  405.     y = shelftop - shelfface - outsidebevel - shelfbevel * 2.0 - shelfheight/5.5;
  406.     pushmatrix();
  407.     translate(0.0, y, -87.0);
  408.     pushmatrix();
  409. #ifdef DEBUG
  410. printf("    pos %d  end %d  \n", pos, endfirstshelf);
  411. #endif
  412.     if (pos < endfirstshelf)
  413.     translate(bookpos[pos]-half, 0.375, 0.0);
  414.     else
  415.     translate(bookpos[pos]-half, 1.0 - (shelfheight + shelfbevel + shelfface), 0.0);
  416.     pushmatrix();
  417.     translate(0.0, 0.0, 5.125);
  418.     rot(180.0, 'y');
  419.     translate(0.0, 0.0, -5.125);
  420.     /* draw arrow */
  421.     bgnpolygon();
  422.        v3f(arrow[0]);
  423.        v3f(arrow[1]);
  424.        v3f(arrow[2]);
  425.     endpolygon();
  426.     bgnpolygon();
  427.        v3f(arrow[6]);
  428.        v3f(arrow[3]);
  429.        v3f(arrow[4]);
  430.     endpolygon();
  431.     bgnpolygon();
  432.        v3f(arrow[6]);
  433.        v3f(arrow[5]);
  434.        v3f(arrow[4]);
  435.     endpolygon();
  436.     popmatrix();
  437.     popmatrix();
  438.     popmatrix();
  439.     dobookview();
  440.  
  441. }
  442.  
  443. void highlightbookonshelf(int thisbook)
  444. {
  445.     float           y;
  446.  
  447.     dooverlayview();
  448.     color(PUP_WHITE);
  449.     y = shelftop - shelfface - outsidebevel - shelfbevel * 2.0 - shelfheight;
  450.     pushmatrix();
  451.     translate(0.0, y, -87.0);
  452.     pushmatrix();
  453.     if (thisbook < endfirstshelf)
  454.     translate(bookpos[thisbook], 0.375, 0.0);
  455.     else
  456.     translate(bookpos[thisbook], 1.0 - (shelfheight + shelfbevel + shelfface), 0.0);
  457.     pushmatrix();
  458.     translate(0.0, 0.0, 5.125);
  459.     rot(180.0, 'y');
  460.     translate(0.0, 0.0, -5.125);
  461.     outlinebinding();
  462.     popmatrix();
  463.     popmatrix();
  464.     popmatrix();
  465.     dobookview();
  466. }
  467.  
  468. void pickdrawbooks()
  469. {
  470.     int             i;
  471.     float           y;
  472.  
  473.     y = shelftop - shelfface - outsidebevel - shelfbevel * 2.0 - shelfheight;
  474.  
  475.     pushmatrix();
  476.     translate(0.0, y, -87.0);
  477.  
  478.     for (i = 0; i < numberofgroups; i++) {
  479.     pushmatrix();
  480.     if (i < endfirstshelf)
  481.         translate(bookpos[i], 0.375, 0.0);
  482.     else
  483.         translate(bookpos[i], 1.0 - (shelfheight + shelfbevel + shelfface), 0.0);
  484.     loadname(i);
  485.     pushmatrix();
  486.     translate(0.0, 0.0, 5.125);
  487.     rot(180.0, 'y');
  488.     translate(0.0, 0.0, -5.125);
  489.     drawbinding();
  490.     popmatrix();
  491.     popmatrix();
  492.     }
  493.     popmatrix();
  494. }
  495.  
  496. void drawbooks()
  497. {
  498.     int             i;
  499.     struct grptmpltstruct *curgrp;
  500.     float           y;
  501.  
  502.     y = shelftop - shelfface - outsidebevel - shelfbevel * 2.0 - shelfheight;
  503.  
  504.     initnames();
  505.     pushmatrix();
  506.     translate(0.0, y, -87.0);
  507.  
  508.     curgrp = firstgroup;
  509.     for (i = 0; i < currentbook; i++) {
  510.     setcovercolor(curgrp);
  511.     pushmatrix();
  512.     if (i < endfirstshelf)
  513.         translate(bookpos[i], 0.375, 0.0);
  514.     else
  515.         translate(bookpos[i], 1.0 - (shelfheight + shelfbevel + shelfface), 0.0);
  516.     loadname(i);
  517.     pushmatrix();
  518.     translate(0.0, 0.0, 5.125);
  519.     rot(180.0, 'y');
  520.     translate(0.0, 0.0, -5.125);
  521.     drawbinding();
  522.         if (curgrp->ok || !Hide)
  523.           drawtitle(curgrp->nameptr->string);
  524.         else
  525.            drawtitle("Not Installed");
  526.     popmatrix();
  527.     popmatrix();
  528.     curgrp = curgrp->nextgrp;
  529.     }
  530.     if (currentbook >= 0)
  531.     curgrp = curgrp->nextgrp;
  532.     for (i = currentbook + 1; i < numberofbooks; i++) {
  533.     setcovercolor(curgrp);
  534.     pushmatrix();
  535.     if (i < endfirstshelf)
  536.         translate(bookpos[i], 0.3755, 0.0);
  537.     else
  538.         translate(bookpos[i], 1.0 - (shelfheight + shelfbevel + shelfface), 0.0);
  539.     loadname(i);
  540.     pushmatrix();
  541.     translate(0.0, 0.0, 5.125);
  542.     rot(180.0, 'y');
  543.     translate(0.0, 0.0, -5.125);
  544.     drawbinding();
  545.         if (curgrp->ok || !Hide)
  546.        drawtitle(curgrp->nameptr->string);
  547.         else
  548.            drawtitle("Not Installed");
  549.     popmatrix();
  550.     popmatrix();
  551.     curgrp = curgrp->nextgrp;
  552.     }
  553.     popmatrix();
  554. }
  555.  
  556. void pickdrawshelves()
  557. {
  558.    pickdrawbooks();
  559. }
  560.  
  561. void drawbookcase()
  562. {
  563.     float           carray[3];
  564.  
  565.     c3s(morecolors[Black]);
  566.     clear();
  567.     setshelfcolor(carray);
  568.     lighten(carray);
  569.     c3f(carray);
  570.     /* left bevel 0,1,2,3 */
  571.     bgnpolygon();
  572.     v3f(shelf[0]);
  573.     v3f(shelf[1]);
  574.     v3f(shelf[2]);
  575.     v3f(shelf[3]);
  576.     endpolygon();
  577.     /* top bevel  3, 2, 4, 5 */
  578.     bgnpolygon();
  579.     v3f(shelf[3]);
  580.     v3f(shelf[2]);
  581.     v3f(shelf[4]);
  582.     v3f(shelf[5]);
  583.     endpolygon();
  584.     /* right bevel 5, 4, 6 ,7 */
  585.     setshelfcolor(carray);
  586.     darken(carray);
  587.     c3f(carray);
  588.     bgnpolygon();
  589.     v3f(shelf[5]);
  590.     v3f(shelf[4]);
  591.     v3f(shelf[6]);
  592.     v3f(shelf[7]);
  593.     endpolygon();
  594.     /* left face 2, 1, 8, 9 */
  595.     setshelfcolor(carray);
  596.     c3f(carray);
  597.     bgnpolygon();
  598.     v3f(shelf[2]);
  599.     v3f(shelf[1]);
  600.     v3f(shelf[8]);
  601.     v3f(shelf[9]);
  602.     endpolygon();
  603.     /* top face 2, 9, 10, 4 */
  604.     bgnpolygon();
  605.     v3f(shelf[2]);
  606.     v3f(shelf[9]);
  607.     v3f(shelf[10]);
  608.     v3f(shelf[4]);
  609.     endpolygon();
  610.     /* right face 4, 10, 11, 6 */
  611.     bgnpolygon();
  612.     v3f(shelf[4]);
  613.     v3f(shelf[10]);
  614.     v3f(shelf[11]);
  615.     v3f(shelf[6]);
  616.     endpolygon();
  617.     /* top shelf left bevel 9, 12, 13, 14 */
  618.     setshelfcolor(carray);
  619.     darken(carray);
  620.     c3f(carray);
  621.     bgnpolygon();
  622.     v3f(shelf[9]);
  623.     v3f(shelf[12]);
  624.     v3f(shelf[13]);
  625.     v3f(shelf[14]);
  626.     endpolygon();
  627.     /* top shelf  top bevel  9, 14, 15, 10 */
  628.     bgnpolygon();
  629.     v3f(shelf[9]);
  630.     v3f(shelf[14]);
  631.     v3f(shelf[15]);
  632.     v3f(shelf[10]);
  633.     endpolygon();
  634.     /* top shelf right bevel 10, 15, 16, 17 */
  635.     setshelfcolor(carray);
  636.     lighten(carray);
  637.     c3f(carray);
  638.     bgnpolygon();
  639.     v3f(shelf[10]);
  640.     v3f(shelf[15]);
  641.     v3f(shelf[16]);
  642.     v3f(shelf[17]);
  643.     endpolygon();
  644.     /* second shelf left bevel 18, 20, 21, 22 */
  645.     setshelfcolor(carray);
  646.     darken(carray);
  647.     c3f(carray);
  648.     bgnpolygon();
  649.     v3f(shelf[18]);
  650.     v3f(shelf[20]);
  651.     v3f(shelf[21]);
  652.     v3f(shelf[22]);
  653.     endpolygon();
  654.     /* second shelf top bevel 18, 22, 23, 19 */
  655.     bgnpolygon();
  656.     v3f(shelf[18]);
  657.     v3f(shelf[22]);
  658.     v3f(shelf[23]);
  659.     v3f(shelf[19]);
  660.     endpolygon();
  661.     /* second shelf right bevel 19, 23, 24, 25 */
  662.     setshelfcolor(carray);
  663.     lighten(carray);
  664.     c3f(carray);
  665.     bgnpolygon();
  666.     v3f(shelf[19]);
  667.     v3f(shelf[23]);
  668.     v3f(shelf[24]);
  669.     v3f(shelf[25]);
  670.     endpolygon();
  671.     /* third shelf left bevel 26, 28, 29, 30 */
  672.     setshelfcolor(carray);
  673.     darken(carray);
  674.     c3f(carray);
  675.     bgnpolygon();
  676.     v3f(shelf[26]);
  677.     v3f(shelf[28]);
  678.     v3f(shelf[29]);
  679.     v3f(shelf[30]);
  680.     endpolygon();
  681.     /* third shelf top bevel 26, 30, 31, 27 */
  682.     bgnpolygon();
  683.     v3f(shelf[26]);
  684.     v3f(shelf[30]);
  685.     v3f(shelf[31]);
  686.     v3f(shelf[27]);
  687.     endpolygon();
  688.     /* third shelf right bevel 27, 31, 32, 33 */
  689.     setshelfcolor(carray);
  690.     lighten(carray);
  691.     c3f(carray);
  692.     bgnpolygon();
  693.     v3f(shelf[27]);
  694.     v3f(shelf[31]);
  695.     v3f(shelf[32]);
  696.     v3f(shelf[33]);
  697.     endpolygon();
  698.  
  699.     drawbooks();
  700.  
  701.     setshelfcolor(carray);
  702.     lighten(carray);
  703.     c3f(carray);
  704.     /* top shelf  bottom bevel 12, 17, 16, 13 */
  705.     bgnpolygon();
  706.     v3f(shelf[12]);
  707.     v3f(shelf[17]);
  708.     v3f(shelf[16]);
  709.     v3f(shelf[13]);
  710.     endpolygon();
  711.     /* face between top two shelves 12, 18, 19, 17 */
  712.     setshelfcolor(carray);
  713.     c3f(carray);
  714.     bgnpolygon();
  715.     v3f(shelf[12]);
  716.     v3f(shelf[18]);
  717.     v3f(shelf[19]);
  718.     v3f(shelf[17]);
  719.     endpolygon();
  720.  
  721.     setshelfcolor(carray);
  722.     lighten(carray);
  723.     c3f(carray);
  724.     /* second shelf bottom bevel 20, 25, 24, 21 */
  725.     bgnpolygon();
  726.     v3f(shelf[20]);
  727.     v3f(shelf[25]);
  728.     v3f(shelf[24]);
  729.     v3f(shelf[21]);
  730.     endpolygon();
  731.     /* second shelf face between second and third shelves 20, 26, 27, 25 */
  732.     setshelfcolor(carray);
  733.     c3f(carray);
  734.     bgnpolygon();
  735.     v3f(shelf[20]);
  736.     v3f(shelf[26]);
  737.     v3f(shelf[27]);
  738.     v3f(shelf[25]);
  739.     endpolygon();
  740. }
  741.  
  742. void initbookpos()
  743. {
  744.    int i;
  745.    float x;
  746.    float center;
  747.    float booksep;
  748.    float start, start2;
  749.    float end;
  750.    int half;
  751.  
  752.    start2 = 0;
  753.    numberofbooks = numberofgroups;
  754.    booksep = 2.25;
  755.    center = 0.0;
  756.    if (numberofbooks > 21)
  757.       {
  758.       half = numberofbooks/2;
  759.       end = (2.25 * half) / 2.0  - 1;
  760.       endfirstshelf = half;
  761.       if (half /2*2 == half)
  762.          start = center - (half / 2) * booksep;
  763.       else 
  764.          start = center - ((float)half / 2.0) * booksep;
  765.       half = numberofbooks-half;
  766.       if (half /2*2 == half)
  767.          start2 = center - (half / 2) * booksep;
  768.       else 
  769.          start2 = center - ((float)half / 2.0) * booksep;
  770.       }
  771.    else
  772.       {
  773.       end = shelfright;
  774.       endfirstshelf = numberofbooks;
  775.       if (numberofbooks / 2 * 2 == numberofbooks)
  776.          {
  777.          start = center - (numberofbooks / 2) * booksep;
  778.          } 
  779.       else
  780.          {
  781.          start = center - ((float)numberofbooks / 2.0) * booksep;
  782.          } 
  783.       } 
  784.    x = start;
  785.    for (i = 0; i < numberofbooks; i++)
  786.       {
  787.       if (x > end)
  788.          x = start2;
  789.       bookpos[i] = x;
  790.       x+=booksep;
  791.       }
  792.    currentbook = -1;
  793. }
  794.  
  795. initshelves()
  796. {
  797.    initflip(0);
  798. /* left bevel 0,1,2,3*/
  799.    shelf[0][0] = shelfleft;
  800.    shelf[0][1] = shelfbottom;
  801.    shelf[0][2] = shelffront;
  802.    shelf[1][0] = shelfleft+outsidebevel;
  803.    shelf[1][1] = shelfbottom;
  804.    shelf[1][2] = shelffront;
  805.    shelf[2][0] = shelfleft+outsidebevel;
  806.    shelf[2][1] = shelftop-outsidebevel;
  807.    shelf[2][2] = shelffront;
  808.    shelf[3][0] = shelfleft;
  809.    shelf[3][1] = shelftop;
  810.    shelf[3][2] = shelffront;
  811. /* top bevel  3, 2, 4, 5*/
  812.    shelf[4][0] = shelfright-outsidebevel;
  813.    shelf[4][1] = shelftop-outsidebevel;
  814.    shelf[4][2] = shelffront;
  815.    shelf[5][0] = shelfright;
  816.    shelf[5][1] = shelftop;
  817.    shelf[5][2] = shelffront;
  818. /* right bevel 5, 4, 6 ,7 */
  819.    shelf[6][0] = shelfright-outsidebevel;
  820.    shelf[6][1] = shelfbottom;
  821.    shelf[6][2] = shelffront;
  822.    shelf[7][0] = shelfright;
  823.    shelf[7][1] = shelfbottom;
  824.    shelf[7][2] = shelffront;
  825. /* left face 2, 1, 8, 9 */
  826.    shelf[8][0] = shelfleft+outsidebevel + shelfface;
  827.    shelf[8][1] = shelfbottom;
  828.    shelf[8][2] = shelffront;
  829.    shelf[9][0] = shelfleft + outsidebevel + shelfface;
  830.    shelf[9][1] = shelftop - outsidebevel - shelfface;
  831.    shelf[9][2] = shelffront;
  832. /* top face 2, 9, 10, 4 */
  833.    shelf[10][0] = shelfright - outsidebevel - shelfface;
  834.    shelf[10][1] = shelftop - outsidebevel - shelfface;
  835.    shelf[10][2] = shelffront;
  836. /* right face 4, 10, 11, 6 */
  837.    shelf[11][0] = shelfright- outsidebevel - shelfface;
  838.    shelf[11][1] = shelfbottom;
  839.    shelf[11][2] = shelffront;
  840. /* inset for top shelf */
  841. /* top shelf left bevel 9, 12, 13, 14 */
  842.    shelf[12][0] = shelfleft + outsidebevel + shelfface;
  843.    shelf[12][1] = shelftop-outsidebevel-shelfface-shelfheight- (shelfbevel*2.0);
  844.    shelf[12][2] = shelffront;
  845.    shelf[13][0] = shelf[12][0] + shelfbevel;
  846.    shelf[13][1] = shelf[12][1] + shelfbevel;
  847.    shelf[13][2] = shelffront;
  848.    shelf[14][0] = shelf[9][0] + shelfbevel;
  849.    shelf[14][1] = shelf[9][1] - shelfbevel;
  850.    shelf[14][2] = shelffront;
  851. /* top shelf  top bevel  9, 14, 15, 10 */
  852.    shelf[15][0] = shelf[10][0] - shelfbevel;
  853.    shelf[15][1] = shelf[14][1];
  854.    shelf[15][2] = shelffront;
  855. /* top shelf right bevel 10, 15, 16, 17 */
  856.    shelf[16][0] = shelf[15][0];
  857.    shelf[16][1] = shelf[13][1];
  858.    shelf[16][2] = shelffront;
  859.    shelf[17][0] = shelf[10][0];
  860.    shelf[17][1] = shelf[12][1];
  861.    shelf[17][2] = shelffront;
  862. /* top shelf  bottom bevel 12, 17, 16, 13 */
  863. /* face between top two shelves 12, 18, 19, 17 */
  864.    shelf[18][0] = shelf[12][0];
  865.    shelf[18][1] = shelf[12][1] - shelfface;
  866.    shelf[18][2] = shelffront;
  867.    shelf[19][0] = shelf[17][0];
  868.    shelf[19][1] = shelf[17][1] - shelfface;
  869.    shelf[19][2] = shelffront;
  870. /* second shelf */
  871. /* second shelf left bevel 18, 20, 21, 22 */
  872.    shelf[20][0] = shelf[12][0];
  873.    shelf[20][1] = shelf[18][1] - shelfbevel*2.0 - shelfheight;
  874.    shelf[20][2] = shelffront;
  875.    shelf[21][0] = shelf[20][0] + shelfbevel;
  876.    shelf[21][1] = shelf[20][1] + shelfbevel;
  877.    shelf[21][2] = shelffront;
  878.    shelf[22][0] = shelf[18][0] + shelfbevel;
  879.    shelf[22][1] = shelf[18][1] - shelfbevel;
  880.    shelf[22][2] = shelffront;
  881. /* second shelf top bevel 18, 22, 23, 19 */
  882.    shelf[23][0] = shelf[19][0] - shelfbevel;
  883.    shelf[23][1] = shelf[19][1] - shelfbevel;
  884.    shelf[23][2] = shelffront;
  885. /* second shelf right bevel 19, 23, 24, 25 */
  886.    shelf[24][0] = shelf[23][0];
  887.    shelf[24][1] = shelf[21][1];
  888.    shelf[24][2] = shelffront;
  889.    shelf[25][0] = shelf[19][0];
  890.    shelf[25][1] = shelf[20][1];
  891.    shelf[25][2] = shelffront;
  892. /* second shelf bottom bevel 20, 25, 24, 21 */
  893. /* second shelf face between second and third shelves 20, 26, 27, 25 */
  894.    shelf[26][0] = shelf[20][0];
  895.    shelf[26][1] = shelf[20][1] - shelfface;
  896.    shelf[26][2] = shelffront;
  897.    shelf[27][0] = shelf[25][0];
  898.    shelf[27][1] = shelf[26][1];
  899.    shelf[27][2] = shelffront;
  900. /* third shelf left bevel 26, 28, 29, 30 */
  901.    shelf[28][0] = shelf[26][0];
  902.    shelf[28][1] = shelf[26][0] - shelfbevel*2.0 - shelfheight;
  903.    shelf[28][2] = shelffront;
  904.    shelf[29][0] = shelf[28][0] + shelfbevel;
  905.    shelf[29][1] = shelf[28][1] + shelfbevel;
  906.    shelf[29][2] = shelffront;
  907.    shelf[30][0] = shelf[26][0] + shelfbevel;
  908.    shelf[30][1] = shelf[26][1] - shelfbevel;
  909.    shelf[30][2] = shelffront;
  910. /* third shelf top bevel 26, 30, 31, 27 */
  911.    shelf[31][0] = shelf[27][0] - shelfbevel;
  912.    shelf[31][1] = shelf[30][1];
  913.    shelf[31][2] = shelffront;
  914. /* third shelf right bevel 27, 31, 32, 33 */
  915.    shelf[32][0] = shelf[31][0];
  916.    shelf[32][1] = shelf[29][1];
  917.    shelf[32][2] = shelffront;
  918.    shelf[33][0] = shelf[32][0] + shelfbevel;
  919.    shelf[33][1] = shelf[28][1];
  920.    shelf[33][2] = shelffront;
  921. /* third shelf bottombevel 29, 28, 33, 32 */
  922.  
  923. }
  924.  
  925.